package com.roc.pan.config;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author roc
 * @date 2023/2/9
 */
@Slf4j
public class ConfigUtils {

    private static Config config = null;

    public static Config getConfig() {
        if (config == null) {
            File configFile = new File("config.json");
            try {
                FileInputStream in = new FileInputStream(configFile);
                int size = in.available();
                byte[] buffer = new byte[size];
                in.read(buffer);
                in.close();
                String strConfig = new String(buffer, "utf-8");
                config = JSON.parseObject(strConfig, Config.class);
            } catch (IOException e) {
                log.error("read config file error :" + e.getMessage());
            }
        }
        return config;
    }
}
